<template>
  <div class="dashboard-container">
    <common-view
      :table-prop="tableProp"
      :form-rules="formRules"
      module-name="roomList"
      :search="getRoomList"
      :add="addRoom"
      :delete="deleteRoom"
      :update="updateRoom"
      :get-form-data="getFormData"
      :get-search-data="getSearchData"
    />

  </div>
</template>

<script>

import CommonView from '@/components/commonView/index'
import { getRoomList, addRoom, deleteRoom, updateRoom } from '@/api/room'

export default {
  name: 'RoomList',
  components: { 'common-view': CommonView },
  data() {
    return {
      getRoomList,
      addRoom,
      deleteRoom,
      updateRoom,
      userList: [],
      professionList: [],
      tableData: [],
      tableProp: [
        {
          prop: 'building',
          label: '楼幢'
          // formatter: value => {
          //   return value.dormitory.building + '幢'
          // }
        },
        {
          prop: 'tablet',
          label: '门牌号'
        }, {
          prop: 'bedNumber',
          label: '床号'
        },
        {
          prop: 'isFree',
          label: '是否空闲'
        }, {
          prop: 'createTime',
          label: '创建时间'
        }, {
          prop: 'updateTime',
          label: '修改时间'
        }
      ],
      formRules: {
        dormitoryId: [
          { required: true, message: '请选择楼幢', trigger: 'change' }
        ],
        tablet: [
          { required: true, message: '请输入门牌号', trigger: 'change' },
          { type: 'number', message: '门牌号只能为数字', trigger: 'change' }
        ],
        bedNumber: [
          { required: true, message: '请输入床号', trigger: 'change' },
          { type: 'number', message: '床号只能为数字', trigger: 'change' }
        ]
      }
    }
  },
  mounted() {
    // 数据初始化
    this.init()
  },
  methods: {
    init() {
      Promise.all([
      ])
    },
    // 新增、编辑表单转换
    getFormData(formData, handle, id) {
      console.log('转换前', formData)
      const { dormitoryId, tablet, bedNumber } = formData
      const newFormData = { dormitoryId, tablet, bedNumber }
      if (handle === 'edit') {
        newFormData['id'] = id
      }
      return newFormData
    },
    // 查询条件转换
    getSearchData(formData) {
      const { building, tablet, isFree } = formData
      return {
        building, tablet, isFree
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.dashboard {
  &-container {
    margin: 30px;
  }
}
</style>
